<?php
// +-------------------------------------------------------------------
// | 
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Admin\Controller;

use Kcdns\Admin\Controller\CommonController;
use Kcdns\Home\Controller\ArticleController;
use Think\Log;

class DyController extends CommonController
{
	
	public function index()
	{
//        var_dump(111);exit();
        $this->display();
	}
	public function dylist()
	{
        $this->assign('type', 1);
        $this->display('dy/kslist');
//        redirect('/kcadmin/dy/kslist?type=1');
//        $this->display();
	}

    public function taobaozhibo(){
        $this->assign('type', 3);
        $this->display('dy/kslist');
//        redirect('/kcadmin/dy/kslist?type=3');
    }

    public function jd(){
        $this->assign('type', 4);
        $this->display('dy/kslist');
//        redirect('/kcadmin/dy/kslist?type=4');
    }

    public function hs(){
        $this->assign('type', 5);
        $this->display('dy/kslist');
//        redirect('/kcadmin/dy/kslist?type=5');
    }

    public function xg(){
        $this->assign('type', 6);
        $this->display('dy/kslist');
//        redirect('/kcadmin/dy/kslist?type=6');
    }

    public function dg(){
        $this->assign('type', 7);
        $this->display('dy/kslist');
//        redirect('/kcadmin/dy/kslist?type=7');
    }

    public function sq(){
        $this->assign('type', 8);
        $this->display('dy/kslist');
//        redirect('/kcadmin/dy/kslist?type=8');
    }




    public function kslist()
    {
        $this->assign('type', 2);
        $this->display('dy/kslist');
       /* if(isset($_GET['type'])){
            $this->display();
        }else{
            redirect('/kcadmin/dy/kslist?type=2');
        }*/

    }
    public function tblist()
    {

        $this->display();
    }
    public function add()
    {

        $this->display();
    }
    public function edit()
    {

        $this->display();
    }
    public function res_add()
    {

        $this->display();
    }

    public function total(){
        echo "<div><span >暂未开放</span></div>";
    }

    public function sourceData(){

        $page_num = I('post.page_num') ?: 1;
        $page_size = I('post.page_size') ?: PAGE_SIZE;
        $vertical_type =  I('post.vertical_type');
        $min_price =  I('post.min_price');
        $max_price =  I('post.max_price');
        $fans_num_min =  I('post.fans_num_min');
        $fans_num_max =  I('post.fans_num_max');
        $keyword =  I('post.keyword');
        $type =  I('post.type');
        if(!$type)    $this->ajaxReturn([
            'code' => -1,
            'msg' => '资源类型不能为空',
        ]);
        $where = [];
        if($vertical_type){
            $where['vertical_type'] = ['in', $vertical_type];
        }
        if($type){
            $where['type'] = $type;
        }
        //报价
        if($min_price == 0 && $max_price>0){
            $where['price'] = [['LT', $max_price]];
        }
        if($min_price >0 && $max_price == 0){
            $where['price'] = [['GT', $min_price]];
        }
        if($min_price >0 && $max_price>0){
            $where['price'] = [['LT', $max_price], ['GT', $min_price]];
        }

        //粉丝数量
        if($fans_num_min == 0 && $fans_num_max>0){
            $where['price'] = [['LT', $fans_num_max]];
        }
        if($fans_num_min >0 && $fans_num_max == 0){
            $where['price'] = [['GT', $fans_num_min]];
        }
        if($fans_num_min >0 && $fans_num_max>0){
            $where['price'] = [['LT', $fans_num_max], ['GT', $fans_num_min]];
        }

        if($keyword) $where['zhubo_nickname'] = [['like', "%{$keyword}%"]];

        $result = (array)M('source')->where($where)->order('id desc')->page($page_num, $page_size)->select();
        $count = M('source')->where($where)->count();
        //合作次数
        $total_work_num = M('source')->where(['type' => $type])->sum('work_num');
        //入驻总数
        $total_num =  M('source')->where($where)->count();
        //已有达人
        $total_daren = M('source')->where(['type' => $type])->count();;
        $level = ['1' => '低','2' => '中','3' => '高'];
        foreach($result as &$item){
            $item['level_text'] = $level[$item['level']];
        }
        $this->ajaxReturn([
            'code' => 1,
            'msg' => '操作成功',
            'data' => [
                'list' => $result,
                'total_work_num' => $total_work_num?$total_work_num:0,
                'total_num' => $total_num?$total_num:0,
                'total_daren' => $total_daren?$total_daren:0,
                'page_num' => $page_num,
                'page_size' => $page_size,
                'page_count' => $count,
                'page_total' => ceil($count / $page_size),
            ],
        ]);
    }

    //资源检测
    public function sourceCheck(){

        $type =  I('post.type');
        $zhubo_nickname =  I('post.zhubo_nickname');
        if(!$type || !$zhubo_nickname) $this->ajaxReturn([
            'code' => -1,
            'msg' => '参数不完整',
        ]);
        $result = M('source')->where([
            'zhubo_nickname' => $zhubo_nickname,
            'type' => $type,
        ])->find();
        if(isset($result['id'])) $this->ajaxReturn([
            'code' => -1,
            'msg' => '该主播已存在',
        ]);
        $this->ajaxReturn([
            'code' => 1,
            'msg' => '操作成功',
        ]);
    }

    public function getTaobaoGoodsDetail()
    {

        $url = TB_JAVA_API."taobao/getGoods";
        $goods_url =  I('post.goods_url');
//        var_dump($url);exit();
//        $goods_url =  "https://item.taobao.com/item.htm?id=566783764461&scm=1007.12144.81309.359572_0_0&pvid=9b1b86dc-917c-4721-874d-a0fb6f48e38e&utparam=%7B%22x_hestia_source%22%3A%22359572%22%2C%22x_object_type%22%3A%22item%22%2C%22x_mt%22%3A9%2C%22x_src%22%3A%22359572%22%2C%22x_pos%22%3A4%2C%22x_pvid%22%3A%229b1b86dc-917c-4721-874d-a0fb6f48e38e%22%2C%22x_object_id%22%3A566783764461%7D";

        $url = $url."?url=".urlencode($goods_url);
        $result = file_get_contents($url);
        $result = json_decode($result, true);
        if($result['code'] == 0){
            $data = [
                'code' => 200,
                'data' => [
                    'goods_url' => $result['data']['item_url'],
                    'goods_title' => $result['data']['title'],
                    'serller_url' => "https://goodfisher.taobao.com/?spm={$result['data']['sellerId']}",
                    'seller_name' => $result['data']['nick'],
                    'seller_id' => $result['data']['sellerId'],
                    'reserve_price' => $result['data']['reserve_price'],
                    'zk_final_price' => $result['data']['zk_final_price'],
                    'pic_url' => $result['data']['pictUrl'],
                ]
            ];
        }else{
            $data = [
                'code' => -1,
                'msg' => '查询失败',
            ];
        }


        $this->ajaxReturn($data, 'json');

    }


    public function sourceAdd(){

        $param = $_POST;
        $user = session('user_auth');

        $zhubo_nickname = I('post.zhubo_nickname');
        $type = I('post.type');

        if(!$param['vertical_type'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '垂直类型不能为空',
        ]);
        if(!$param['avatar'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '主播头像不能为空',
        ]);
        if(!$param['no'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '账号不能为空',
        ]);
        if(!$param['zhubo_nickname'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '主播名称不能为空',
        ]);
        if(!$param['service_hang'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '服务领域不能为空',
        ]);
        if(!$param['price'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '报价不能为空',
        ]);
        if(!is_numeric($param['price'])) $this->ajaxReturn([
            'code' => -1,
            'msg' => '填写的报价格式存在问题',
        ]);
        if(!$param['fans_num'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '粉丝数量不能为空',
        ]);
        if(!is_string($param['fans_num'])) $this->ajaxReturn([
            'code' => -1,
            'msg' => '粉丝数量填写格式不正确',
        ]);
        if(!isset($param['schedule']))  $this->ajaxReturn([
            'code' => -1,
            'msg' => '排期不能为空',
        ]);
        if(!$param['addressee'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '收件人不能为空',
        ]);
        if(!$param['contact'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '联系方式不能为空',
        ]);
        if(!$param['address'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '收货地址不能为空',
        ]);
        /*if(!$param['work_num'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '合作次数不能为空',
        ]);*/
        if(!is_numeric($param['work_num'])) $this->ajaxReturn([
            'code' => -1,
            'msg' => '合作次数填写的格式不正确',
        ]);
        /*if(!$param['organization_avatar'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '机构头像不能为空',
        ]);*/
        if(!$param['organization'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '所属机构不能为空',
        ]);
        if(!$param['type'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '类型不能为空',
        ]);
        $flag = M('source')->where(['zhubo_nickname' => $zhubo_nickname,'type' => $type])->find();
        if($flag) $this->ajaxReturn([
            'code' => -1,
            'msg' => '主播名称已存在',
        ]);

        $param = $_POST;
        $param['mid'] = $user['uid'];
        $flag = M('source')->add($param);
        if(!$flag)  $this->ajaxReturn([
            'code' => -1,
            'msg' => '操作失败',
        ]);
        $this->ajaxReturn([
            'code' => 200,
            'msg' => '操作成功',
        ]);
    }

    //资源编辑
    public function sourceSave(){

        $param = $_POST;
        /*$save = [
            "service_hang" => $param['service_hang'],
            "price" => $param['price'],
            "fans_num" => $param['fans_num'],
            "contact" => $param['contact'],
            "schedule" => $param['schedule'],
            "address" => $param['address'],
            "organization_avatar" => $param['organization_avatar'],
            "organization" => $param['organization'],
            "vertical_type" => $param['vertical_type'],
        ];*/
        $detail = M('source')->where(['id' => $param['source_id']])->find();
        if(!$detail) $this->ajaxReturn([
            'code' => -1,
            'msg' => '未找到记录',
        ]);
        $flag = M('source')->where(['id' => $param['source_id']])->save($param);
        if(!$flag)  $this->ajaxReturn([
            'code' => -1,
            'msg' => '操作失败',
        ]);
        $this->ajaxReturn([
            'code' => 200,
            'msg' => '操作成功',
        ]);
    }

    //资源详情
    public function sourceDetail(){

        $param = $_POST;
        /*$save = [
            "service_hang" => $param['service_hang'],
            "price" => $param['price'],
            "fans_num" => $param['fans_num'],
            "contact" => $param['contact'],
            "schedule" => $param['schedule'],
            "address" => $param['address'],
            "organization_avatar" => $param['organization_avatar'],
            "organization" => $param['organization'],
            "vertical_type" => $param['vertical_type'],
        ];*/
        $flag = M('source')->where(['id' => $param['source_id']])->find();
        if(!$flag)  $this->ajaxReturn([
            'code' => -1,
            'msg' => '未找到记录',
        ]);
        $this->ajaxReturn([
            'code' => 200,
            'msg' => '操作成功',
            'data' => $flag
        ]);
    }

    public function activityGoodsAdd(){

        $param = $_POST;
        if(!$param['activity_code'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '活动code参数不能为空',
        ]);
        if(!$param['activity_title'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => '活动名称参数不能为空',
        ]);
     /*   if(!$param['start_time'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'start_time参数不能为空',
        ]);
        if(!$param['end_time'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'end_time参数不能为空',
        ]);*/
        if(!$param['goods_url'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'goods_url参数不能为空',
        ]);
        if(!$param['goods_title'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'goods_title参数不能为空',
        ]);
        if(!$param['serller_url'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'serller_url参数不能为空',
        ]);
        if(!$param['seller_name'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'seller_name参数不能为空',
        ]);
        if(!$param['seller_id'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'seller_id参数不能为空',
        ]);
        if(!$param['reserve_price'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'reserve_price参数不能为空',
        ]);
        if(!$param['zk_final_price'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'zk_final_price参数不能为空',
        ]);
       /* if(!$param['coupon_price'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'coupon_price参数不能为空',
        ]);
        if(!$param['coupon_back_price'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'coupon_back_price参数不能为空',
        ]);*/
        if(!$param['reward_radio'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'reward_radio参数不能为空',
        ]);
        if(!$param['service_radio'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'service_radio参数不能为空',
        ]);
       /* if(!$param['coupon_pic'])  $this->ajaxReturn([
            'code' => -1,
            'msg' => 'coupon_pic参数不能为空',
        ]);*/
        $user = session('user_auth');
        $param['uid'] = $user['uid'];
        if(!$param['state']) $param['state'] = 0;
        $flag = M('zs_activity_goods')->add($param);
        if(!$flag)  $this->ajaxReturn([
            'code' => -1,
            'msg' => '发布失败',
        ]);
        $this->ajaxReturn([
            'code' => 200,
            'msg' => '操作成功',
        ]);
    }

    public function activityGoodsDetail(){

        $param = $_POST;
        $flag = M('zs_activity_goods')->where(['id' => $param['id']])->find();
        if(!$flag)  $this->ajaxReturn([
            'code' => -1,
            'msg' => '未找到记录',
        ]);
        $this->ajaxReturn([
            'code' => 200,
            'msg' => '操作成功',
            'data' => $flag
        ]);
    }

    public function activityGoodsSave(){

        $param = $_POST;
        $id = $param['id'];
        $detail = M('zs_activity_goods')->where(['id' => $param['id']])->find();
        if(!$detail) $this->ajaxReturn([
            'code' => -1,
            'msg' => '未找到记录',
        ]);
        /*$save = [
            "service_hang" => $param['service_hang'],
            "price" => $param['price'],
            "fans_num" => $param['fans_num'],
            "contact" => $param['contact'],
            "schedule" => $param['schedule'],
            "address" => $param['address'],
            "organization_avatar" => $param['organization_avatar'],
            "organization" => $param['organization'],
            "vertical_type" => $param['vertical_type'],
        ];*/
        $flag = M('zs_activity_goods')->where(['id' => $id])->save($param);
        if(!$flag)  $this->ajaxReturn([
            'code' => -1,
            'msg' => '操作失败',
        ]);
        $this->ajaxReturn([
            'code' => 200,
            'msg' => '操作成功',
        ]);
    }

    public function activityGoodsData(){

        $page_num = I('post.page_num') ?: 1;
        $page_size = I('post.page_size') ?: PAGE_SIZE;
        $state =  I('post.state');
        $keyword =  I('post.keyword');
        $where = [];
        if($state)    $where['state'] = $state;

        if($state == 0) $where['state'] = 0;

        if($keyword) $where['activity_title'] = [['like', "%{$keyword}%"]];

        $result = (array)M('zs_activity_goods')->where($where)->order('id desc')->page($page_num, $page_size)->select();
        $count = M('zs_activity_goods')->where($where)->count();
        //待排期数量
        $total_goods_daipaiqi = M('zs_activity_goods')->where(['state' =>1])->count();
        //结束商品数量
        $total_goods_over = M('zs_activity_goods')->where(['state' =>3])->count();
        //本月总数据
        $total_mouth =  M('zs_activity_goods')->sum('jieyu_money');
        //本月待结算
        $total_mouth_settling =  M('zs_activity_goods')->where(['state' =>1])->sum('jieyu_money');
        //本月已结算
        $total_mouth_settled = M('zs_activity_goods')->where(['state' =>4])->sum('jieyu_money');
        //待排期
        $total_daipaiqi = M('zs_activity_goods')->where(['state' =>1])->count();
        //进行中
        $total_going = M('zs_activity_goods')->where(['state' =>2])->count();
        //已结束
        $total_over = M('zs_activity_goods')->where(['state' =>3])->count();
        //已结算
        $total_settle = M('zs_activity_goods')->where(['state' =>4])->count();
        //已拒绝
        $total_refuse = M('zs_activity_goods')->where(['state' =>5])->count();
        //待审核
        $total_dengdai = M('zs_activity_goods')->where(['state' =>0])->count();
        //等待推广
        $total_dengdai_promote = M('zs_activity_goods')->where(['state' =>6])->count();
        //操作按钮控制
        $yewu = 23;
        $caiwu = 18;
        $user = session('user_auth');
        foreach($result as &$item){
            $item['is_edit'] = 2;
            $promote =  [
                'status' => 2,
                'is_tg' => 2,
                'url' => 'activityPromote',
                'text' => '立即推广'
            ];
            $over =  [
                'status' => 2,
                'is_tg' => 2,
                'url' => 'activityOver',
                'text' => '结束操作'
            ];
            $settle =  [
                'status' => 2,
                'is_tg' => 2,
                'url' => 'activitySettle',
                'text' => '结算操作'
            ];
            $refuse =  [
                'status' => 2,
                'is_tg' => 2,
                'url' => 'activityRefuse',
                'text' => '拒绝操作'
            ];
            $pass =  [
                'status' => 2,
                'is_tg' => 2,
                'url' => 'activityPass',
                'text' => '审核通过'
            ];
            $paiqi =  [
                'status' => 2,
                'is_tg' => 2,
                'url' => 'activityPaiqi',
                'text' => '确认排期'
            ];
            if($item['state'] == 0){
                $pass['status'] = 1;
                $refuse['status'] = 1;
                $item['is_edit'] = 1;
            }elseif($item['state'] == 1){
                $item['is_edit'] = 1;
                $paiqi['status'] = 1;
            }elseif($item['state'] == 6){
                $item['is_edit'] = 1;
                $promote['status'] = 1;
            }elseif($item['state'] == 2){
                $over['status'] = 1;
            }elseif($item['state'] == 3){
                $settle['status']= 1;
            }
            if($item['state'] ==5) $item['is_edit'] = 1;

            //业务部门
            if($user['group_id'] == $yewu){
                $item['is_edit'] = 2;
                $settle['status'] = 2;
            }
            //财务部门
            if($user['group_id'] == $caiwu){
                $item['is_edit'] = 2;
                if($settle['status'] != 2) $settle['status'] = 1;
                $pass['status'] = 2;
                $paiqi['status'] = 2;
                $promote['status'] = 2;
                $over['status'] = 2;
                $refuse['status'] = 2;
            }
            $item['btn'] = [$pass, $paiqi, $promote, $over, $settle, $refuse];
            $item['create_time'] = date('Y.m.d', strtotime($item['create_time']));
        }
        $this->ajaxReturn([
            'code' => 1,
            'msg' => '操作成功',
            'data' => [
                'list' => $result,
                'total_goods_daipaiqi' => $total_goods_daipaiqi?$total_goods_daipaiqi:0,
                'total_goods_over' => $total_goods_over?$total_goods_over:0,
                'total_mouth' => $total_mouth?$total_mouth:0.00,
                'total_mouth_settling' => $total_mouth_settling?$total_mouth_settling:0.00,
                'total_mouth_settled' => $total_mouth_settled?$total_mouth_settled:0.00,
                'total_daipaiqi' => $total_daipaiqi?$total_daipaiqi:0,
                'total_going' => $total_going?$total_going:0,
                'total_over' => $total_over?$total_over:0,
                'total_settle' => $total_settle?$total_settle:0,
                'total_refuse' => $total_refuse?$total_refuse:0,
                'total_dengdai' => $total_dengdai?$total_dengdai:0,
                'total_dengdai_promote' => $total_dengdai_promote?$total_dengdai_promote:0,
                'page_num' => $page_num,
                'page_size' => $page_size,
                'page_count' => $count,
                'page_total' => ceil($count / $page_size),
            ],
        ]);
    }

    //立即推广
    public function activityPromote(){

        $param = $_POST;
        if(!$param['id'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => 'ID不能为空',
            ]);
        if(!$param['coupon_url'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '优惠券链接不能为空',
            ]);
        if(!$param['coupon_price'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '券金额不能为空',
            ]);
        if(!$param['coupon_back_price'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '券后价不能为空',
            ]);
        if(!$param['coupon_pic'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '券图不能为空',
            ]);

        $detail = M('zs_activity_goods')->where(['id' =>$param['id']])->find();
        if(!$detail['id'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '记录是空的',
            ]);
        if($detail['state'] == 2)
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '已结束',
            ]);
        $flag = M('zs_activity_goods')->where(['id' => $param['id']])->save([
            'state' => 2,
            'coupon_url' => $param['coupon_url'],
            'coupon_price' => $param['coupon_price'],
            'coupon_back_price' => $param['coupon_back_price'],
            'coupon_pic' => $param['coupon_pic'],
        ]);
        if ($flag === false) {
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '操作失败',
            ]);

        } else {
            $this->ajaxReturn([
                'code' => 200,
                'msg' => '操作成功',
            ]);
        }

    }

    //结束操作
    public function activityOver()
    {

        $param = $_POST;
        if (!$param['id'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => 'ID不能为空',
            ]);
        if (!$param['over_data'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '结束数据不能为空',
            ]);
        if (!$param['over_pic'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '结束图不能为空',
            ]);
        $detail = M('zs_activity_goods')->where(['id' => $param['id']])->find();
        if (!$detail['id'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '记录是空的',
            ]);
        if ($detail['state'] == 3)
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '已结束',
            ]);
        $flag = M('zs_activity_goods')->where(['id' => $param['id']])->save([
            'state' => 3,
            'over_data' => $param['over_data'],
            'over_pic' => $param['over_pic'],
        ]);
        if ($flag === false) {
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '操作失败',
            ]);

        } else {
            $this->ajaxReturn([
                'code' => 200,
                'msg' => '操作成功',
            ]);
        }
    }

    //结算操作
    public function activitySettle()
    {

        $param = $_POST;
        if (!$param['id'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => 'ID不能为空',
            ]);
        if (!$param['total_money'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '总费用不能为空',
            ]);
        if (!$param['total_money_pic'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '总费用收款图不能为空',
            ]);
        if (!$param['zhichu_money'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '支出费用不能为空',
            ]);
        if (!$param['zhichu_pic'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '支出费用图片不能为空',
            ]);
        $detail = M('zs_activity_goods')->where(['id' => $param['id']])->find();
        if (!$detail['id'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '记录是空的',
            ]);
        if ($detail['state'] == 4)
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '已结算',
            ]);
        $flag = M('zs_activity_goods')->where(['id' => $param['id']])->save([
            'state' => 4,
            'total_money' => $param['total_money'],
            'total_money_pic' => $param['total_money_pic'],
            'zhichu_money' => $param['zhichu_money'],
            'zhichu_pic' => $param['zhichu_pic'],
            'jieyu_money' => $param['total_money']-$param['zhichu_money'],
        ]);
        if ($flag === false) {
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '操作失败',
            ]);

        } else {
            $this->ajaxReturn([
                'code' => 200,
                'msg' => '操作成功',
            ]);
        }
    }

    //拒绝操作
    public function activityRefuse()
    {

        $param = $_POST;
        if (!$param['id'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => 'ID不能为空',
            ]);
        if (!$param['refuse_reason'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '拒绝理由不能为空',
            ]);
        $detail = M('zs_activity_goods')->where(['id' => $param['id']])->find();
        if (!$detail['id'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '记录是空的',
            ]);
        if ($detail['state'] == 5)
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '已结算',
            ]);
        $flag = M('zs_activity_goods')->where(['id' => $param['id']])->save([
            'state' => 5,
            'refuse_reason' => $param['refuse_reason'],
        ]);
        if ($flag === false) {
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '操作失败',
            ]);

        } else {
            $this->ajaxReturn([
                'code' => 200,
                'msg' => '操作成功',
            ]);
        }
    }


    //审核通过操作
    public function activityPass()
    {

        $param = $_POST;
        if (!$param['id'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => 'ID不能为空',
            ]);

        $detail = M('zs_activity_goods')->where(['id' => $param['id']])->find();
        if (!$detail['id'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '记录是空的',
            ]);
        if ($detail['state'] != 0)
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '已审核',
            ]);
        $flag = M('zs_activity_goods')->where(['id' => $param['id']])->save([
            'state' => 1,
        ]);
        if ($flag === false) {
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '操作失败',
            ]);

        } else {
            $this->ajaxReturn([
                'code' => 200,
                'msg' => '操作成功',
            ]);
        }
    }

    //拒绝操作
    public function activityPaiqi()
    {

        $param = $_POST;
        if (!$param['id'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => 'ID不能为空',
            ]);
        if (!$param['start_time'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '开始时间不能为空',
            ]);
        if (!$param['end_time'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '结束时间不能为空',
            ]);
        $detail = M('zs_activity_goods')->where(['id' => $param['id']])->find();
        if (!$detail['id'])
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '记录是空的',
            ]);
        if ($detail['state'] == 6)
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '已确认排期',
            ]);
        $flag = M('zs_activity_goods')->where(['id' => $param['id']])->save([
            'state' => 6,
            'end_time' => $param['end_time'],
            'start_time' => $param['start_time'],
        ]);
        if ($flag === false) {
            $this->ajaxReturn([
                'code' => -1,
                'msg' => '操作失败',
            ]);

        } else {
            $this->ajaxReturn([
                'code' => 200,
                'msg' => '操作成功',
            ]);
        }
    }

}